/*
  Copyright 2011 the JSDoc Authors.

  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

      https://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
*/
describe('@constructs tag', () => {
  it('When a symbol has a @constructs tag, it is documented as a class with that name.', () => {
    const docSet = jsdoc.getDocSetFromFile('test/fixtures/constructstag.js');
    const textblock = docSet.getByLongname('TextBlock')[0];

    expect(textblock.kind).toBe('class');
    expect(textblock.longname).toBe('TextBlock');
  });

  it('When a symbol has a @constructs tag, it is documented as a class.', () => {
    const docSet = jsdoc.getDocSetFromFile('test/fixtures/constructstag2.js');
    const menu = docSet.getByLongname('Menu')[0];

    expect(menu.name).toBe('Menu');
    expect(menu.kind).toBe('class');
  });

  it('When a function symbol has a @constructs tag, any this-variables are ducumented as instance members of the class.', () => {
    const docSet = jsdoc.getDocSetFromFile('test/fixtures/constructstag3.js');
    const personName = docSet.getByLongname('Person#name')[0];

    expect(personName.memberof).toBe('Person');
    expect(personName.scope).toBe('instance');
  });

  it('When a function symbol has a @constructs tag with no value, in a @lends block with a "Name#" value, the function is documented as a constructor of "Name".', () => {
    const docSet = jsdoc.getDocSetFromFile('test/fixtures/constructstag4.js');
    const person = docSet.getByLongname('Person').filter(({ undocumented }) => !undocumented)[0];

    expect(person.kind).toBe('class');
  });

  it('When a function symbol has a @constructs tag with no value, any this-variables are documented as instance members of the class.', () => {
    const docSet = jsdoc.getDocSetFromFile('test/fixtures/constructstag4.js');
    const personName = docSet.getByLongname('Person#name')[0];

    expect(personName.memberof).toBe('Person');
    expect(personName.scope).toBe('instance');
  });

  it('When a object literal property has a @constructs tag with no value, and the object has a @lends, the property is documented as the lent class.', () => {
    const docSet = jsdoc.getDocSetFromFile('test/fixtures/constructstag5.js');
    const duck = docSet.getByLongname('Duck').filter(({ undocumented }) => !undocumented)[0];

    expect(duck.longname).toBe('Duck');
    expect(duck.kind).toBe('class');
    expect(duck.description).toBe('Constructs a duck.');
  });
});
